package com.ymatou.iapi.accounting.service;

import com.ymatou.utils.EnvSetup;
import com.ymt.base.YmatouBaseCall;
import com.ymt.core.tool.Logger;
import org.json.JSONException;
import org.json.JSONObject;
/**
*根据用户编号和账户类型获取账户余额接口Call
*FreeMaker Template自动生成代码
*/
public class GetAccountBalanceCall extends YmatouBaseCall{
	private static String opurl ="api/Account/GetAccountBalance";
	
	public GetAccountBalanceCall() {
		super(EnvSetup.getSystemUrl("accounting_iapi"),opurl,"POST","JSON");
	}
	@Override
	public void addDefHeader() {
		client.addHeader("Accept","text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}
	
	//获取 accountid
	public String getAccountId() {
		String cid = null;
		try {
			cid = new JSONObject(getReturnData()).getJSONObject("Data").getString("AccountId");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return cid;
	}
	
	//获取 Status
	public int getStatus() {
		int status = 0;
		try {
			status = new JSONObject(getReturnData()).getInt("StatusCode");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return status;
	}
	
	//获取 data
	public JSONObject getData() {
		JSONObject data = null;
		try {
			data = new JSONObject(getReturnData()).getJSONObject("Data");
		} catch (JSONException e) {
			Logger.debug("GetAccountBalanceCall return data is null!");
		}
		return data;
	}
	
	//获取 msg
	public String getMsg() {
		String msg = null;
		try {
			msg = new JSONObject(getReturnData()).optString("Message");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return msg;
	}
	//获取 AvailAmount
	public String getAvailAmount() {
		String availAmount = null;
		try {
			availAmount = getData().optString("AvailAmount");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return availAmount;
	}
	//获取 FreezeAmount
	public String getFreezeAmount() {
		String freezeAmount = null;
		try {
			freezeAmount = getData().optString("FreezeAmount");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return freezeAmount;
	}
}